package cn.com.haopy.dataes.hbase.config;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.HBaseConfiguration;

import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

import java.io.IOException;


/**
 * HBase配置
 */
@org.springframework.context.annotation.Configuration
public class HbaseConfig {

    @Value("${hbase.zookeeper.quorum}")
    private String quorum;
    @Value("${hbase.zookeeper.property.clientPort}")
    private String clientPort;

    @Bean(name = "hbaseConfiguration")
    public Configuration hbaseConfiguration() {
        System.out.println("---------quorum:---------" + quorum);
        Configuration configuration = HBaseConfiguration.create();
        configuration.set("hbase.zookeeper.quorum", quorum);
        configuration.set("hbase.zookeeper.property.clientPort", clientPort);
        return configuration;
    }


/*   @Bean
    public HbaseTemplate hbaseTemplate() {
        return new HbaseTemplate(hbaseConfiguration());

    }*/

    /*@Bean
    public Connection getConnection() throws IOException {
        Connection connection = null;
        connection = ConnectionFactory.createConnection(hbaseConfiguration());
        //Admin admin =connection.getAdmin();
        return connection;
    }*/

    @Bean
    public Admin admin() {
        Admin admin = null;
        try {
            Connection connection = ConnectionFactory.createConnection(hbaseConfiguration());
            admin = connection.getAdmin();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return admin;
    }

    /**
     @Bean public HBaseAdminService hBaseAdminService() throws IOException {
     //设置临时的hadoop环境变量，之后程序会去这个目录下的\bin目录下找winutils.exe工具，windows连接hadoop时会用到
     //System.setProperty("hadoop.home.dir", "D:\\Program Files\\Hadoop");
     //执行此步时，会去resources目录下找相应的配置文件，例如hbase-site.xml
     org.apache.hadoop.conf.Configuration conf = HBaseConfiguration.create();
     return new HBaseAdminService(conf);
     }**/
}